// 无重复区间
var eraseOverlapIntervals = function(intervals) {
    intervals.sort((a,b)=> a[1]-b[1])
    console.log(intervals)
    const n = intervals.length
    let j = 0;
    let count = 0;
    for(let i = 1; i < n && j < n;) {
        while(intervals[j][1]>intervals[i][0]) {
            ++count;
            ++i
        }
        j=i;
        i++;
    }
    return count;
};
// 题解
// var eraseOverlapIntervals = function(intervals) {
//     intervals.sort((a, b) => {
//         return a[1] - b[1]
//     })

//     let count = 1
//     let end = intervals[0][1]

//     for(let i = 1; i < intervals.length; i++) {
//         let interval = intervals[i]
//         if(interval[0] >= end) {
//             end = interval[1]
//             count += 1
//         }
//     }
    
//     return intervals.length - count
// };
console.log(eraseOverlapIntervals([[0,2],[1,3],[2,4],[3,5],[4,6]]))